package com.zxy.ziems.server.classify.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.classify.mapper.ClassifyDevicePropertyMapper;
import com.zxy.ziems.server.classify.pojo.entity.ClassifyDeviceProperty;
import com.zxy.ziems.server.classify.pojo.param.ClassifyDevicePropertyPageParam;
import com.zxy.ziems.server.classify.service.ClassifyDevicePropertyService;
import com.zxy.ziems.server.mybatis.core.service.ServiceImplX;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ClassifyDevicePropertyServiceImpl extends ServiceImplX<ClassifyDevicePropertyMapper, ClassifyDeviceProperty> implements ClassifyDevicePropertyService {
    @Override
    public List<ClassifyDeviceProperty> getByClassId(String classifyId) {
        QueryWrapper<ClassifyDeviceProperty> param = new QueryWrapper<>();
        param.lambda().eq(ClassifyDeviceProperty::getClassifyId, classifyId);
        return baseMapper.selectList(param);
    }

    @Override
    public List<ClassifyDeviceProperty> getByClassifyIdAndDeviceId(String classifyId, String deviceId) {
        QueryWrapper<ClassifyDeviceProperty> param = new QueryWrapper<>();
        param.lambda().eq(ClassifyDeviceProperty::getClassifyId, classifyId)
                .eq(ClassifyDeviceProperty::getDeviceId, deviceId);
        return baseMapper.selectList(param);
    }


    @Override
    public List<ClassifyDeviceProperty> getByClassIds(List<String> classifyId) {
        QueryWrapper<ClassifyDeviceProperty> param = new QueryWrapper<>();
        param.lambda().in(ClassifyDeviceProperty::getClassifyId, classifyId);
        return baseMapper.selectList(param);
    }

    @Override
    public Long countByDeviceId(String deviceId) {
        QueryWrapper<ClassifyDeviceProperty> param = new QueryWrapper<>();
        param.lambda().eq(ClassifyDeviceProperty::getDeviceId, deviceId);
        return baseMapper.selectCount(param);
    }

    @Override
    public ClassifyDeviceProperty getByClassifyIdAndDeviceIdAndDataTypeId(String classifyId, String deviceId, String dataTypeId) {
        QueryWrapper<ClassifyDeviceProperty> param = new QueryWrapper<>();
        param.lambda().eq(ClassifyDeviceProperty::getClassifyId, classifyId)
                .eq(ClassifyDeviceProperty::getDeviceId, deviceId)
                .eq(ClassifyDeviceProperty::getDataTypeId, dataTypeId);
        return baseMapper.selectOne(param);
    }

    @Override
    public void deleteById(String id) {
        removeById(id);
    }

    @Override
    public PageResult<ClassifyDeviceProperty> pageListBy(ClassifyDevicePropertyPageParam param) {
        PageResult<ClassifyDeviceProperty> result = customPage(param, (p, aParam) -> baseMapper.queryPageList(p, aParam));
        if (CollectionUtil.isEmpty(result.getList())) {
            return new PageResult<>(0L, new ArrayList<>());
        }

        return result;
    }


//    private DeviceService deviceService;
//
//    @Autowired
//    public void setDeviceService(DeviceService deviceService) {
//        this.deviceService = deviceService;
//    }


}
